﻿using HuaWei;
using HuaWei.CommClass;
using HuaWei.Common;
using HuaWei.Windows.Forms;
using System;
using System.Collections;
using System.Data;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows.Forms;

internal class Class31 : Class30, Interface1
{
    private string _str3 = null;
    private SJLX sjlx;

    public bool imethod_0(string _str4, string _str5)
    {
        return true;
    }

    public bool imethod_1([Optional, DefaultParameterValue(false)] bool _flag)
    {
        if (this.sjlx.Equals(SJLX.JG))
        {
            string exeStr = "";
            base.ida.OpenDatabase();
            base.ida.BeginTrans();
            try
            {
                exeStr = "delete from XMJBXXEX";
                base.ida.ExecuteNonQuery(exeStr, CommandType.Text);
                exeStr = exeStr = "delete from ZZJGXXEX";
                base.ida.ExecuteNonQuery(exeStr, CommandType.Text);
                exeStr = exeStr = "delete from CTFL where bdid='-1'";
                base.ida.ExecuteNonQuery(exeStr, CommandType.Text);
                exeStr = exeStr = "delete from GCLCT where bdid='-1'";
                base.ida.ExecuteNonQuery(exeStr, CommandType.Text);
                exeStr = "delete from JLQD";
                base.ida.ExecuteNonQuery(exeStr, CommandType.Text);
                exeStr = "delete from CLQD";
                base.ida.ExecuteNonQuery(exeStr, CommandType.Text);
                DataSet dsUpdate = new DataSet();
                string str2 = "";
                string str3 = "";
                exeStr = "select * from ZZJGXX";
                DataTable dt = DBHelp.GetDt(exeStr, "ZZJGXX");
                str2 = DHelp.GetIds(dt, "id", "");
                str3 = DHelp.GetIds(dt, "xmid", "");
                exeStr = "select * from XMJBXXEX where 1=2";
                dsUpdate.Merge(base.ida.ExecuteDataSet(exeStr, CommandType.Text, "XMJBXXEX"));
                base.CopyImportData(dsUpdate, base.dataSet, "XMJBXXEX", "id in (" + str3 + ")");
                exeStr = "select * from ZZJGXXEX where 1=2";
                dsUpdate.Merge(base.ida.ExecuteDataSet(exeStr, CommandType.Text, "ZZJGXXEX"));
                base.CopyImportData(dsUpdate, base.dataSet, "ZZJGXXEX", "id in (" + str2 + ")");
                exeStr = "select * from CTFL where 1=2";
                dsUpdate.Merge(base.ida.ExecuteDataSet(exeStr, CommandType.Text, "CTFL"));
                base.CopyImportData(dsUpdate, base.dataSet, "CTFL", "");
                exeStr = "select * from GCLCT where 1=2";
                dsUpdate.Merge(base.ida.ExecuteDataSet(exeStr, CommandType.Text, "GCLCT"));
                base.CopyImportData(dsUpdate, base.dataSet, "GCLCT", "");
                exeStr = "select * from JLQD where 1=2";
                dsUpdate.Merge(base.ida.ExecuteDataSet(exeStr, CommandType.Text, "JLQD"));
                base.CopyImportData(dsUpdate, base.dataSet, "JLQD", "bdid in (" + str2 + ")");
                exeStr = "select * from CLQD where 1=2";
                dsUpdate.Merge(base.ida.ExecuteDataSet(exeStr, CommandType.Text, "CLQD"));
                base.CopyImportData(dsUpdate, base.dataSet, "CLQD", "bdid in (" + str2 + ")");
                if ((_flag && (GParams.QCInfo.QCID != null)) && !GParams.QCInfo.QCID.Equals(""))
                {
                    exeStr = string.Format("update DATAUPDATE set qcid={0} where id='ImportGLYData' and bdid='{1}'", GParams.QCInfo.QCID, GParams._BDID);
                    base.ida.ExecuteNonQuery(exeStr, CommandType.Text);
                }
                base.ida.Update(dsUpdate, true);
                base.ida.Commit();
                Class28.smethod8(base.ida);
                MsgBox.ShowMsg("导入机构信息已完成！");
                return true;
            }
            catch (Exception exception)
            {
                base.ida.RollBack();
                MsgBox.ShowError("数据包不正确，请重新选择！", exception);
            }
            finally
            {
                base.ida.CloseDatabase();
            }
        }
        else
        {
            MsgBox.ShowMsg("无效的数据包，请重新选择机构信息包！");
        }
        return false;
    }

    public bool imethod_2(SJLX sjlx1)
    {
        string destPath = AppDomain.CurrentDomain.BaseDirectory + "CRFile";
        OpenFileDialog dialog = new OpenFileDialog();
        dialog.Filter = "ZIP文件(*.zip)|*.zip";
        if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
        {
            return false;
        }
        this._str3 = dialog.FileName;
        string path = FileZip.unzipFile(this._str3, destPath, "", true);
        string[] strArray = Path.GetFileNameWithoutExtension(path).Split(new char[] { 'z' });
        SJLX sjlx = (SJLX) Convert.ToInt16(strArray[0].ToString());
        if (!sjlx1.Equals(SJLX.Non) && !sjlx1.Equals(sjlx))
        {
            MsgBox.ShowMsg("请选择正确的数据包后继续此操作!");
            return false;
        }
        string fileId = strArray[1];
        string qcid = strArray[2];
        string sid = strArray[3];
        if (!base.DataCheck(fileId, sid, sjlx, qcid))
        {
            return false;
        }
        if (!(path.Equals("") || !File.Exists(path)))
        {
            switch (sjlx)
            {
                case SJLX.YZSP:
                    return this.imethod_4(path);

                case SJLX.JL:
                    return this.imethod_3(path);

                case SJLX.JG:
                    return this.imethod_1(true);

                case SJLX.BGL:
                    return this.imethod_5(path);
            }
        }
        File.Delete(path);
        string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(this._str3);
        string extension = Path.GetExtension(this._str3);
        string destFileName = destPath + @"\" + fileNameWithoutExtension + extension;
        File.Copy(this._str3, destFileName, true);
        return true;
    }

    public bool imethod_3(string _str4)
    {
        DataSet set = new DataSet();
        set.ReadXml(_str4, XmlReadMode.ReadSchema);
        DataSet set2 = new DataSet();
        base.ida.OpenDatabase();
        base.ida.BeginTrans();
        try
        {
            if (this.imethod_6(set, set2, true))
            {
                if (!GParams.DZYZ)
                {
                    base.ImportTable(set, set2, "BGL", " where bdid='#bdid#'");
                    base.ImportTable(set, set2, "BGLQD", " where bdid='#bdid#'");
                }
                base.ImportTable(set, set2, "JLQD", string.Format(" where bdid='{0}'", base.BDID));
                base.ImportTable(set, set2, "CLQD", string.Format(" where bdid='{0}'", base.BDID));
                base.ImportTableByIds(set, set2, "XMJBXXEX");
                base.ImportTableByIds(set, set2, "ZZJGXXEX");
                base.ImportTable(set, set2, "CTFL", string.Format(" where bdid='-1' or bdid='{0}'", base.BDID));
                base.ImportTable(set, set2, "GCLCT", string.Format(" where bdid='-1' or bdid='{0}'", base.BDID));
                base.ImportLocalData(set, set2);
                if (set2.HasChanges())
                {
                    base.ida.Update(set2, true);
                    base.ida.Commit();
                    MsgBox.ShowMsg("导入计量数据已完成！");
                }
            }
        }
        catch (Exception exception)
        {
            base.ida.RollBack();
            MsgBox.ShowError("导入数据时出错，请与管理员系统！", exception);
        }
        if (this.YfQclfhSo())
        {
            Class28.smethod8(base.ida);
            return true;
        }
        return false;
    }

    public bool imethod_4(string _str4)
    {
        if (base.method() && base.method5())
        {
            DataSet dsSource = new DataSet();
            dsSource.ReadXml(_str4, XmlReadMode.ReadSchema);
            string exeStr = "";
            base.ida.OpenDatabase();
            base.ida.BeginTrans();
            try
            {
                DataSet ds = new DataSet();
                string tableName = "";
                DataTable tDt = null;
                DataTable empDt = null;
                DataTable table3 = null;
                DataTable table4 = null;
                foreach (TableInfo info in base.tableInfoList)
                {
                    DataRow row2;
                    tableName = info.TableName;
                    table3 = dsSource.Tables[tableName];
                    if (table3 != null)
                    {
                        exeStr = base.BuildSQLParam("delete from " + tableName + " where bdid='#bdid#' and qcid='#qcid#'");
                        base.ida.ExecuteNonQuery(exeStr, CommandType.Text);
                        tDt = base.GetEmpDt(ds, tableName);
                        if (table3 != null)
                        {
                            foreach (DataRow row in table3.Rows)
                            {
                                row2 = DHelp.CopyItemArray(tDt, row, false);
                                row2["SID"] = base.SID;
                                row2.EndEdit();
                            }
                        }
                    }
                    tableName = info.TableName + "2";
                    if (info.Boolean)
                    {
                        table4 = dsSource.Tables[tableName];
                        if (table4 != null)
                        {
                            exeStr = base.BuildSQLParam("delete from " + tableName + " where bdid='#bdid#' and qcid='#qcid#'");
                            base.ida.ExecuteNonQuery(exeStr, CommandType.Text);
                            empDt = base.GetEmpDt(ds, tableName);
                            if ((table4 != null) && (table3 != null))
                            {
                                foreach (DataRow row in table3.Rows)
                                {
                                    row2 = DHelp.CopyItemArray(empDt, row, false);
                                    row2["SID"] = base.SID;
                                    row2.EndEdit();
                                }
                            }
                        }
                    }
                }
                base.method4(1);
                base.ImportTable(dsSource, ds, "BGL", " where bdid='#bdid#'");
                base.ImportTable(dsSource, ds, "BGLQD", " where bdid='#bdid#'");
                base.ImportTable(dsSource, ds, "JLQD", " where bdid='#bdid#'");
                base.ImportTable(dsSource, ds, "CLQD", " where bdid='#bdid#'");
                base.ImportTable(dsSource, ds, "XMJBXXEX", "");
                base.ImportTable(dsSource, ds, "ZZJGXXEX", "");
                base.ImportTable(dsSource, ds, "CTFL", "");
                base.ImportTable(dsSource, ds, "GCLCT", "");
                base.ImportTable(dsSource, ds, "REP_GCBG", string.Format(" where bdid='{0}' and qcid={1}", base.BDID, base.QCID));
                base.ImportTable(dsSource, ds, "REP_ZQZFZS", string.Format(" where bdid='{0}' and qcid={1}", base.BDID, base.QCID));
                base.ida.Update(ds, true);
                base.ida.Commit();
                MsgBox.ShowMsg("导入数据已完成!!");
                return true;
            }
            catch (Exception exception)
            {
                base.ida.RollBack();
                MsgBox.ShowError("导入数据出错，请与管理员系统！", exception);
            }
            finally
            {
                base.ida.CloseDatabase();
            }
        }
        return false;
    }

    public bool imethod_5(string _str4)
    {
        if (base.method())
        {
            DataSet dsSource = new DataSet();
            dsSource.ReadXml(_str4, XmlReadMode.ReadSchema);
            base.ida.OpenDatabase();
            base.ida.BeginTrans();
            try
            {
                DataSet dsUpdate = new DataSet();
                base.ImportTable(dsSource, dsUpdate, "BGL", " where bdid='#bdid#'");
                base.ImportTable(dsSource, dsUpdate, "BGLQD", " where bdid='#bdid#'");
                base.ImportTable(dsSource, dsUpdate, "JLQD", " where bdid='#bdid#' and zbcd=1");
                base.ida.Update(dsUpdate, true);
                base.ida.Commit();
                MsgBox.ShowMsg("导入变更令已完成！");
                return true;
            }
            catch (Exception exception)
            {
                base.ida.RollBack();
                MsgBox.ShowError("导入变更令出错，请与管理员系统！", exception);
            }
            finally
            {
                base.ida.CloseDatabase();
            }
        }
        return false;
    }

    public bool imethod_6(DataSet dataSet1, DataSet dataSet2, bool _flag)
    {
        DataTable table = dataSet1.Tables["XMQC"];
        if (table == null)
        {
            goto Label_01C1;
        }
        string format = "select * from xmqc where bdid='{0}' order by qcid";
        format = string.Format(format, base.BDID);
        DataTable dt = base.ExecuteDataSetEx(dataSet2, format, "XMQC");
        if (_flag)
        {
            string key = string.Empty;
            DataRow row = null;
            IEnumerator enumerator = dt.Rows.GetEnumerator();
            {
                DataRow current;
                while (enumerator.MoveNext())
                {
                    current = (DataRow) enumerator.Current;
                    key = current["id"].ToString();
                    if (current["zt"].Equals("0"))
                    {
                        row = table.Rows.Find(key);
                        if ((row != null) && row["zt"].Equals("1"))
                        {
                            goto Label_00D3;
                        }
                    }
                }
                goto Label_0114;
            Label_00D3:
                MsgBox.ShowMsg(string.Format("承包人第{0}期已接收业主数据，请接收业主的数据后再接收承包人数据！", current["qcid"].ToString()));
                return false;
            }
        }
    Label_0114:
        if (table != null)
        {
            string str3 = DHelp.GetIds(dt, "qcid", "");
            if (!str3.Equals(""))
            {
                table.DefaultView.RowFilter = " qcid not in (" + str3 + ")";
            }
            foreach (DataRow row2 in table.DefaultView.ToTable().Rows)
            {
                dt.Rows.Add(row2.ItemArray);
            }
        }
        GParams._QCData = table;
    Label_01C1:
        return true;
    }

    public void method7(string _str4)
    {
        this._str3 = _str4;
        string destPath = AppDomain.CurrentDomain.BaseDirectory + "CRFile";
        string sourceFileName = _str4;
        string path = FileZip.unzipFile(sourceFileName, destPath, "", true);
        string[] strArray = Path.GetFileNameWithoutExtension(path).Split(new char[] { 'z' });
        this.sjlx = (SJLX) Convert.ToInt16(strArray[0].ToString());
        base.dataSet.ReadXml(path, XmlReadMode.ReadSchema);
    }

    public bool method8()
    {
        OpenFileDialog dialog = new OpenFileDialog();
        dialog.Filter = "ZIP文件(*.zip)|*.zip";
        if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
        {
            this._str3 = dialog.FileName;
            return this.method8();
        }
        return false;
    }

    private bool YfQclfhSo()
    {
        try
        {
            FrmChangeData data = new FrmChangeData();
            data.SID = base.SID;
            data.QCID = base.QCID;
            data.BDID = base.BDID;
            if (data.IniForm(base.tableInfoList) && (data.ShowDialog() != System.Windows.Forms.DialogResult.OK))
            {
            }
        }
        catch
        {
            return false;
        }
        return true;
    }
}

